<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * This is the controller for register form
 *
 * @author		akjmgalp
 * @Revision	From SVN
 */

// ------------------------------------------------------------------------
class Signup extends CI_Controller {
	
	public function index() {
		$data = array("main_view" => "signup_form");
		$this->load->view('templates/default/template', $data);
	}
	
	public function submit() {
		
		if ($this->_submit_validate() === FALSE) {
			$this->index();
			return;
		}

		$u = new User();
		$u->username = $this->input->post('username');
		$u->password = $this->input->post('password');
		$u->email = $this->input->post('email');
		$u->save();
		
		$data = array("main_view" => "submit_success");
		$this->load->view('templates/default/template', $data);
	
	}
	
	private function _submit_validate() {
		
		$this->form_validation->set_rules('username', 'Kullanıcı Adı', 
			'required|alpha_numeric|min_length[6]|max_length[12]|unique[User.username]');
		
		$this->form_validation->set_rules('password', 'Şifre',
			'required|min_length[1]|max_length[12]');
		
		$this->form_validation->set_rules('passconf', 'Şifre Tekrar',
			'required|matches[password]');
		
		$this->form_validation->set_rules('email', 'E-mail',
			'required|valid_email|unique[User.email]');
		
		return $this->form_validation->run();
	}
	
}
